/*package org.jack.bluetooth;

import java.io.IOException;
import java.io.InputStream;
import java.util.UUID;

import org.jack.activity.R;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothServerSocket;
import android.bluetooth.BluetoothSocket;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;

public class BluetoothServer 
{
	private final static String TAG = BluetoothServer.class.getSimpleName();
	public final static int DISCOVERY = 0X1;
	private Handler handler = null;
	private BluetoothAdapter bluetooth = null;
	private Activity activity = null;
	private BluetoothServerSocket server = null;
	private BluetoothSocket socket = null;
	private SetupThread setupThread = null;
	private ReadThread readThread = null;
	public static final String PROTOCOL_SCHEME_RFCOMM = "btspp";
	
	public BluetoothServer(Context arg_context)
	{
		activity = (Activity) arg_context;
		handler = new Handler()
		{
			
			@Override
			public void handleMessage(Message msg)
			{
				Log.d(TAG, "Show message:" + msg.obj.toString());
				Toast.makeText(activity, msg.obj.toString(), Toast.LENGTH_SHORT).show();
			}
			
		};
		Log.d(TAG, "Get bluetooth...");
		bluetooth = BluetoothAdapter.getDefaultAdapter();
		if (null == bluetooth)
		{
			return;
		}
		Log.d(TAG, "Local address : " + bluetooth.getAddress());
		if (!bluetooth.isEnabled())
		{
			Message msg = new Message();
			msg.obj = "当前设备上没有蓝牙!";
			handler.sendMessage(msg);
			return;
		}
	}
	
	public void setup()
	{
		Message msg = new Message();
		msg.obj = "正在启动服务器";
		handler.sendMessage(msg);
		
		setupThread = new SetupThread();
		setupThread.start();
	}
	public void teardown()
	{

		try {
			if (null != readThread)
			{
				readThread.interrupt();
			}
			if (null != setupThread)
			{
				setupThread.interrupt();
			}
			if (null != socket)
			{
				socket.close();
			}
			if (null != server)
			{
				server.close();
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally
		{
			readThread = null;
			setupThread = null;
			socket = null;
			server = null;
		}
		
	}
	private class SetupThread extends Thread
	{
		@Override
		public void run() {
			try {
				server = bluetooth.listenUsingRfcommWithServiceRecord(PROTOCOL_SCHEME_RFCOMM, 
						UUID.fromString(activity.getResources().getString(R.string.uuid)));
				Message msg = new Message();
				msg.obj = "服务器已经启动,等待客户连接...";
				handler.sendMessage(msg);
				
				socket = server.accept();
				
				msg = new Message();
				msg.obj = "已经有客户连接:" + socket.getRemoteDevice().getAddress();
				handler.sendMessage(msg);	
				readThread = new ReadThread();
				readThread.start();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	private class ReadThread extends Thread
	{

		@Override
		public void run() 
		{
			byte[] buffer = new byte[1024];
			int bytes = 0;
			InputStream is = null;
			try {
				is = socket.getInputStream();
				while (true)
				{
					if ((bytes = is.read(buffer)) > 0)
					{
						byte[] buf_data = new byte[bytes];
						for (int i = 0; i < bytes; i++)
						{
							buf_data[i] = buffer[i];
						}
						Message msg = new Message();
						msg.obj = "已接收到客户端数据:" + new String(buf_data);
						handler.sendMessage(msg);
					}
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally
			{
				try {
					if (null != is)
					{
						is.close();
					}
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
	}
}
*/